package com.hzw.saas.common.security.config.customer;

import com.hzw.saas.common.config.configuration.properties.SaasHostProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 默认配置
 * 资源服务器，可重写，改变资源服务器ID以及白名单URL
 * 用@Primary修饰重写类
 * 并添加配置
 * spring:
 *   main:
 *     allow-bean-definition-overriding: true
 * @author sonam
 * @sine 2021/11/3 11:20 上午
 */
@Service
@RequiredArgsConstructor
public class DefaultSaasSecurityConfig implements SaasSecurityConfig {

    private final SaasHostProperties ignoredUrlsProperties;

    @Override
    public String resourceId() {
        return "saas-service";
    }

    @Override
    public List<String> ignoreAuthUrls() {
        List<String> ignoreAuthUrls = new ArrayList<>(ignoredUrlsProperties.getIgnoreAuthUrls());
        ignoreAuthUrls.add("/ws/**");
        ignoreAuthUrls.add("/saas/oauth/**");
        return ignoreAuthUrls;
    }

    @Override
    public List<String> ignoreStaticUrls() {
        return Arrays.asList("/webjars/**",
            "/swagger/**",
            "/swagger-ui.html",
            "/v2/api-docs",
            "/v2/api-docs-ext",
            "/doc.html",
            "/swagger-resources/**",
            "/js/**",
            "/css/**");
    }
}
